package com.zzh.dp;

public class No303_NumArray {
    public static void main(String[] args) {
        NumArray numArray = new NumArray(new int[]{1, 2, 3, 4, 5});
        int sum = numArray.sumRange(1, 2);
        System.out.println(sum);
    }
}
class NumArray {

    private final int[] sum;
    public NumArray(int[] nums) {
        sum=new int[nums.length+1];
        sum[0]=0;
        for (int i=0;i<nums.length;i++){
            sum[i+1]=sum[i]+nums[i];
        }
    }

    public int sumRange(int i, int j) {
        return sum[j+1]-sum[i];
    }
}
